package com.tech.koufu.ui.adapter;

import java.util.ArrayList;

import com.tech.koufu.R;
import com.tech.koufu.model.StockInfo;
import com.tech.koufu.model.UserStocks;
import com.tech.koufu.ui.adapter.ExpertsShowAdapter.ViewHolder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class SimpleStockAdapter extends BaseAdapter {

	private Context context;  
	private LayoutInflater mInflater = null; 
	public ArrayList<UserStocks> datas;
	public int type = 0;
	
	public  SimpleStockAdapter(Context context,ArrayList<UserStocks> datas) {
		this.context = context;
		this.mInflater = LayoutInflater.from(context);
		this.datas = datas;
	}
	@Override
	public int getCount() {
		if(null!=datas){
			return datas.size();
		}else{
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		 ViewHolder holder = null;  
         //如果缓存convertView为空，则需要创建View  
         if(convertView == null)  
         {  
             holder = new ViewHolder();  
             //根据自定义的Item布局加载布局  
             convertView = mInflater.inflate(R.layout.lv_item_sell, parent,false);  
             holder.txt_stock_name = (TextView)convertView.findViewById(R.id.txt_stock_name);  
             holder.txt_stock_code = (TextView)convertView.findViewById(R.id.txt_stock_code);   
             holder.txt_stock_sellnum = (TextView)convertView.findViewById(R.id.txt_stock_sellnum);  
             holder.txt_stock_sellnum_value = (TextView)convertView.findViewById(R.id.txt_stock_sellnum_value);  
             
             //将设置好的布局保存到缓存中，并将其设置在Tag里，以便后面方便取出Tag  
             convertView.setTag(holder);  
         }else  
         {  
             holder = (ViewHolder)convertView.getTag();  
         }  
         UserStocks stockInfo = (UserStocks) getItem(position);
         holder.txt_stock_name.setText(stockInfo.getStockName());
         holder.txt_stock_code.setText(stockInfo.getStockId());  
   	  	 holder.txt_stock_sellnum.setText(stockInfo.getStockbj());
         if(type==0){
        	 holder.txt_stock_sellnum_value .setText(stockInfo.getStockHold());
         }else{//盈利率
        	 
         }
         
         return convertView;
	}

	static class ViewHolder  
    {    
        public TextView txt_stock_name;  
        public TextView txt_stock_code;   
        public TextView txt_stock_sellnum;
        public TextView txt_stock_sellnum_value;
        
    }  
}
